package com.wenlin.myproduction.ui;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.wenlin.myproduction.R;
import com.wenlin.myproduction.base.BaseActivity;
import com.wenlin.myproduction.base.BaseSwipeActivity;
import com.wenlin.myproduction.util.UI;
import com.wenlin.myproduction.util.ValCommon;
import com.wenlin.myproduction.widget.MosaicView;

import butterknife.BindView;

/**
 * @author 文琳
 * @Email 377979485@qq.com
 * @desc 马赛克控件演示页
 * @time 2023-12-27 周三 12:11
 */
public class MosaicViewActivity extends BaseSwipeActivity {
    @BindView(R.id.iv_ori)
    ImageView ivOri;
    @BindView(R.id.mv)
    MosaicView mv;

    private Bitmap bitmap;

    public static void start(BaseActivity activity) {
        Intent intent = new Intent(activity, MosaicViewActivity.class);
        if (activity != null && !activity.isDestroyed() && !activity.isFinishing())
            activity.startActivity(intent);
    }

    @Override
    public int getContentView() {
        return R.layout.activity_mosaic_view;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(ValCommon.MOSAIC_VIEW);
        try {
            Glide.with(this).asDrawable().load("https://tcs.teambition.net/thumbnail/312238f4234e97973d0781b8232a06a252b1/w/200/h/200").error(R.mipmap.ic_image_error).into(new SimpleTarget<Drawable>() {
                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    bitmap = ((BitmapDrawable) resource).getBitmap();
                    ivOri.setImageBitmap(bitmap);
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    if (errorDrawable != null) {
                        bitmap = ((BitmapDrawable) errorDrawable).getBitmap();
                        ivOri.setImageBitmap(bitmap);
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        mv.setImageUrl("https://tcs.teambition.net/thumbnail/312238f4234e97973d0781b8232a06a252b1/w/200/h/200");
    }
}
